home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 024 / conquest / conqmo.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  9KB  |  188 lines

  1. #include "defs.h"
  2. #include "structs.h"
  3. #include "vars.h"
  4. #include <stdio.h>
  5.  
  6.  
  7. lose_q(Ship9s, typ, percent)
  8. int *Ship9s;
  9. char typ;
  10. float percent;
  11. {
  12.         int i,sleft;
  13.         int ships;
  14.  
  15.         ships = *Ship9s;
  16.         sleft = ships;
  17.         if ( ships > 0 )
  18.                 for ( i = 1 ; i<=ships; i++ )
  19.                         if ( ((float)(rand()&0x7fff)/(float)(0x7fff)) > percent )
  20.                                 sleft = sleft - 1;
  21.         *Ship9s = sleft;
  22. }
  23.  
  24. move_ships()
  25. {
  26.         float ratio, prob; 
  27.         int there,dx,dy,i; 
  28.         tteam tm; 
  29.         struct stplanet *pplanet;
  30.         boolean any, loss;
  31.         /*clear the board*/
  32.         for ( i = 1 ; i<=26; i++ ) {
  33.                 if ( (tf[player][i].dest != 0) && (tf[player][i].eta != 0) ) {
  34.                         board[tf[player][i].x][tf[player][i].y].tf = ' ';
  35.                         update_board(tf[player][i].x,tf[player][i].y,right);
  36.                 };
  37.         };
  38.         /*move ships of both teams*/
  39.         tm = ENEMY;
  40.         do {
  41.                 for ( i=1 ; i<=26; i++ ) {
  42.                         if ( (tf[tm][i].dest != 0) && (tf[tm][i].eta != 0) ) {
  43.                                 tf[tm][i].eta=tf[tm][i].eta-1;
  44.                                 if((!stars[tf[tm][i].dest].visit[tm]) &&
  45.                                         (tf[tm][i].eta == 0) &&
  46.                                         (tm == player)) {
  47.  
  48.                                         left_line[20] = true;
  49.                                         cle3r_left();
  50.                                         point(1,19);
  51.                                         printf("Task force %c exploring %c.\n", '`'+i, 
  52.                                                 tf[tm][i].dest + '@');
  53.                                         prob = (t_e_prob + rnd(t_e_var) * tf[tm][i].t) / 100.0;
  54.                                         if(tf[tm][i].s != 0)
  55.                                                 prob = (s_e_prob + rnd(s_e_var) * tf[tm][i].s) / 100.0;
  56.                                         if(tf[tm][i].c != 0)
  57.                                                 prob = (c_e_prob + rnd(c_e_var) * tf[tm][i].c) / 100.0;
  58.                                         if(tf[tm][i].b != 0)
  59.                                                 prob = (b_e_prob + rnd(b_e_var) * tf[tm][i].b) / 100.0;
  60.                                         if(prob > 100) prob=100;
  61.                                         loss = true;
  62.                                         lose(&tf[tm][i].t, &loss, 't', prob);
  63.                                         lose(&tf[tm][i].s, &loss, 's', prob);
  64.                                         lose(&tf[tm][i].c, &loss, 'c', prob);
  65.                                         lose(&tf[tm][i].b, &loss, 'b', prob);
  66.                                         if(loss) printf("No ships");
  67.                                         printf(" destroyed.");
  68.                     left_line[23] = true;
  69.                                         pause();
  70.                                         tf[tm][i].eta = 1;      /* fool zero tf */
  71.                                         zero_tf(tm, i);
  72.                                         tf[tm][i].eta = 0;      /* fool zero tf */
  73.                                         }
  74.                                 if(tf[tm][i].dest != 0) {
  75.                                         if ( tm==player ) {
  76.                                                 dx= stars[tf[tm][i].dest].x;
  77.                                                 dy= stars[tf[tm][i].dest].y;
  78.                                                 ratio = 1.0 - ((float)tf[tm][i].eta / tf[tm][i].origeta);
  79.                                                 tf[tm][i].x = tf[tm][i].xf + round(ratio*(dx-tf[tm][i].xf));
  80.                                                 tf[tm][i].y = tf[tm][i].yf +round(ratio *(dy-tf[tm][i].yf));
  81.                                                 if ( (tf[tm][i].eta ==0)  ) {
  82.                                                         pplanet = stars[tf[tm][i].dest].first_planet;
  83.                                                         while (pplanet != nil) {
  84.                                                                 pplanet->psee_capacity = pplanet->capacity;
  85.                                                                 pplanet = pplanet->next;
  86.                                                         }
  87.                                                         player_arrivals[tf[tm][i].dest]=true;
  88.                                                         if ( ! stars[tf[tm][i].dest].visit[tm] ) {
  89.                                                                 board[tf[tm][i].x][tf[tm][i].y].enemy=' ';
  90.                                                                 update_board(tf[tm][i].x,tf[tm][i].y,left);
  91.                                                                 stars[tf[tm][i].dest].visit[tm]=true;
  92.                                                         };
  93.                                                 };
  94.                                         };
  95.                                         if ( (tm==ENEMY) && (tf[tm][i].eta==0) ) {
  96.                                                 pplanet=stars[tf[tm][i].dest].first_planet;
  97.                                                 stars[tf[tm][i].dest].visit[ENEMY]=true;
  98.                                                 while ( pplanet!=nil ) {
  99.                                                         pplanet->esee_team = pplanet->team;
  100.                                                         pplanet=pplanet->next;
  101.                                                 };
  102.                                                 if ( tf_stars[tf[tm][i].dest][ENEMY]>0 ) {
  103.                                                         there=1;
  104.                                                         while ( (there== i) || (tf[ENEMY][there].dest!=tf[ENEMY][i]
  105.                                                             .dest) || (tf[ENEMY][there].eta!=0) ) there=there+1;
  106.                                                         joinsilent(ENEMY,&tf[ENEMY][i],&tf[ENEMY][there]);
  107.                                                 };
  108.                                                 if ( (tf_stars[tf[tm][i].dest][player]>0) ||
  109.                                                     (col_stars[tf[tm][i].dest][player]>0) )
  110.                                                         enemy_arrivals[tf[tm][i].dest]=true;
  111.                                         };
  112.                                         if ( (tf[tm][i].eta==0)  )
  113.                                                 tf_stars[tf[tm][i].dest][tm] ++;
  114.                                 };
  115.                         };
  116.                 };
  117.                 tm++;
  118.         } 
  119.         while (tm != none);
  120.         /* put the good guys on the board*/
  121.         for ( i=1 ; i<=26; i++ ) {
  122.                 if ( tf[player][i].dest != 0 ) {
  123.                         tf[player][i].blasting = false;
  124.                         dx=tf[player][i].x;
  125.                         dy = tf[player][i].y;
  126.                         if ( board[dx][dy].tf == ' ' )
  127.                                 board[dx][dy].tf = i+'a'-1;
  128.                         else if ( board[dx][dy].tf != i+'a'-1)
  129.                                 board[dx][dy].tf='*';
  130.                         update_board(dx,dy,right);
  131.                 };
  132.         };
  133.         any = false;
  134.         for ( i= 1 ; i<=nstars;i++ ) {
  135.                 if ( player_arrivals[i] ) {
  136.                         if ( (! any)  ) {
  137.                                 point(33,21);
  138.                                 printf("Player arrivals :               ");
  139.                                 point(50,21);
  140.                                 any = true;
  141.                         };
  142.                         putchar(i+'A'-1);
  143.                         player_arrivals[i]=false;
  144.                 };
  145.         };
  146.         if ( (! any) && (terminal_type != hardcopy) ) {
  147.                 point(33,21);
  148.                 printf(blank_line);
  149.         };
  150.         any = false;
  151.         for ( i= 1 ; i<=nstars; i++ ) {
  152.                 if ( enemy_arrivals[i] ) {
  153.                         if ( (! any)  ) {
  154.                                 point(33,22);
  155.                                 printf("Enemy arrivals  :               ");
  156.                                 point(50,22);
  157.                                 any = true;
  158.                         };
  159.                         putchar(i+'A'-1);
  160.                         enemy_arrivals[i]=false;
  161.                 };
  162.         };
  163.         if ( (! any) && (terminal_type != hardcopy)  ) {
  164.                 point(33,22);
  165.                 printf(blank_line);
  166.         };
  167.         any = false;
  168.         for ( i = 1 ; i<=nstars; i++ ) {
  169.                 if ( en_departures[i] ) {
  170.                         if ( ! any ) {
  171.                                 point(33,23);
  172.                                 printf("Enemy departures:               ");
  173.                                 point(50,23);
  174.                                 any = true;
  175.                         };
  176.                         putchar(i+'A'-1);
  177.                         en_departures[i]=false;
  178.                 };
  179.         };
  180.         if ( (! any) && (terminal_type != hardcopy) ) {
  181.                 point(33,23);
  182.                 printf(blank_line);
  183.         };
  184.         for ( i= 1 ; i<=nstars; i++ )
  185.                 revolt(i);
  186. }
  187.  
  188.